package com.dc.entity;


import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.util.Date;
import java.util.Objects;

/**
 *  6-1-涂装喷漆-喷漆房分段喷漆  单船工序   子表
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name = "t_workflow_paint_house_child")
public class WorkflowPaintHouseChildEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name = "device", length = 50)
    private String device;          // 设备


    @Column(name = "start_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Temporal(TemporalType.TIMESTAMP)
    private Date startTime;         // 开始时间

    @Column(name = "end_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Temporal(TemporalType.TIMESTAMP)
    private Date endTime;           // 结束时间

    @Column(name = "num")
    private Integer num;            // 数量

    @Column(name = "unit", length = 10)
    private String unit;            // 单位

    @Column(name = "power")
    public Double power;           // 设备功率(KW)

    @Column(name = "total_power")
    public Double totalPower;      // 总有功电能(KWH)   =(endTime-beginTime) * 24 * num * power


    @Transient
    private Long pid;     // 传递 workflow_paint_house_id 参数

    // persist对级联新增有影响，remove对级联删除有影响，merge对级联修改有影响，refresh对级联查询有影响
    @JsonIgnoreProperties(value = { "inner" })
    @JsonIgnore
    @ManyToOne()
    @JoinColumn(name = "workflow_paint_house_id", referencedColumnName = "id")
    private WorkflowPaintHouseEntity workflowPaintHouseEntity;


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        WorkflowPaintHouseChildEntity that = (WorkflowPaintHouseChildEntity) o;
        return Objects.equals(id, that.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }

    @Override
    public String toString() {
        return "WorkflowPaintHouseChildEntity{" +
                "id=" + id +
                ", device='" + device + '\'' +
                ", startTime=" + startTime +
                ", endTime=" + endTime +
                ", num=" + num +
                ", unit='" + unit + '\'' +
                ", power=" + power +
                ", totalPower=" + totalPower +
                ", pid=" + pid +
                '}';
    }
}
